String.prototype.replaceAll = function(s1, s2){ 
	return this.replace(new RegExp(s1, "gm"), s2); 
};
String.prototype.isBlank = function(){
	var s = $.trim(this);
	if(s == "undefined" || s == null || s == "" || s.length == 0){
		return true;
	}
	return false;
};
var _skin = 'layui-layer-lan';
RM={};
RM.height = function(){
	if (window.innerHeight!=window.undefined)//FF
	{
		return window.innerHeight;
	}
	if (document.compatMode=='CSS1Compat')//IE
	{
		return document.documentElement.clientHeight;
	}
	if (document.body)//other
	{
		return document.body.clientHeight; 
	}
	return window.undefined; 
};
RM.msg = function(message){
	window.top.layer.msg(message, {
		time : 2000
	});
};
RM.alert = function(message, fun){
	parent.layer.alert(message, {
		icon: 1,
		skin: _skin,
		end : function(){
			if(fun){
				fun();
			}
		}
	});
};
RM.tips = function(message, id){
	parent.layer.tips(message, id);
};
RM.load = function(){
	var index = parent.layer.load(1, {
		time: 0,
		scrollbar: false,
		shade: [0.5, '#393D49']
	});
	return index;
};
RM.top = function(message){
	parent.layer.msg(message, {
	  offset: 0,
	  shift: 6
	});
};
RM.confirm = function(message, ok, canel){
	var index = parent.layer.confirm(message, {
			btn: ['确认','取消'], //按钮
			skin: _skin
		}, function(){
			if(ok){
				ok();
			}
		}, function(){
			if(canel){
				canel();
			}
		}
	);
	return index;
};
RM.dialog = function(title, html,width ){
	if(width == null){
		width = 500;
	}
	layer.open({
		type: 1,
		title: title,
		closeBtn: 0,
		offset: '100px',
		shadeClose: true,
		skin: _skin,
		content: html,
		area: [width+'px'],
	});
}

RM.logout = function(){
	RM.confirm('确认是否退出', function(){
		location.href = '/logout.do';
	});
};
RM.open = function(title, url,width,heigth,fun){
	var index = parent.layer.open({
		type: 2,
		skin: _skin,
		title: title,
		maxmin: false,
		shade: [0.8, '#393D49'],
		area: [width+'px', heigth+'px'],
		content: url,
		end: function(){
			if(fun){
				fun();
			}
		}
	});
	return index;
};
RM.close = function(index){
	if(index){
		parent.layer.close(index);
	}else{
		layer.closeAll();
		parent.layer.closeAll();
	}
};
RM.ajax = function(url, data, success, error){
	var index = RM.load();
	$.post(url, data, function(data){
		RM.close(index);
		if(data.code == 0){
			if(success){
				success(data);
			}else{
				RM.alert("操作成功", function(){
					parent.location.reload();
				});
			}
		}else{
			if(error){
				error(data);
			}else{
				if(data.code == '501'){
					RM.alert(data.message);
				}else{
					RM.alert("操作失败" + data.code);
				}
			}
		}
	});
};
RM.jqgrid = {
	ids : function(grid){
		var ids = grid.jqGrid('getGridParam','selarrrow');
		return ids;
	},
	dels : function (grid , url){
		var ids = RM.jqgrid.ids(grid);
		if(ids.length == 0){
			RM.alert("请至少选择一行进行删除");
			return false;
		}
		RM.confirm("确认删除所选的"+ids.length+"条记录吗?", function (){
			var index = RM.load();
			RM.ajax(url, {"ids":ids},function (data){
				RM.close(index);
				if(data.code == 0){
					RM.alert("操作成功", function(){
						//grid.jqGrid("setGridParam", queryData).trigger("reloadGrid")
						grid.jqGrid().trigger("reloadGrid");
					});
				}else{
					RM.alert("操作失败" + data.code);
				}
			});
		});
	},
	reload : function ( grid ){
		grid.jqGrid().trigger("reloadGrid");
	}
};

RM.btn = {
	add : function (btn , grid){
		var _title = btn.attr("data-title");
		var _url = btn.attr("data-url");
		var _width = btn.attr("data-width");
		var _height = btn.attr("data-height");
		var index = RM.open(_title,_url,_width,_height,function (){
			RM.jqgrid.reload(grid);
		});
		window.parent.window.setSingleCheckMenuTreeParentIndex(index);
	},
	edit : function (btn , grid , id){
		var _title = btn.attr("data-title");
		var _url = btn.attr("data-url") + "?id=" + id;
		var _width = btn.attr("data-width");
		var _height = btn.attr("data-height");
		var index = RM.open(_title,_url,_width,_height,function (){
			RM.jqgrid.reload(grid);
		});
		window.parent.window.setSingleCheckMenuTreeParentIndex(index);
	}
};

RM.role = {
	
};
